﻿using System;
using System.IO;

namespace DumpArgs
{
    class Program
    {
        private const string DumpExtension = ".txt";

        static void Main(string[] args)
        {
            DateTime dateTime = DateTime.Now;
            if (args != null)
            {
                string fileName = string.Format("DumpArgs_{0}{1}{2}-{3}{4}_{5}", dateTime.Year.ToString("0000"),
                                                dateTime.Month.ToString("00"), dateTime.Day.ToString("00"),
                                                dateTime.Hour.ToString("00"), dateTime.Minute.ToString("00"),
                                                dateTime.Second.ToString("00"));
                string exeLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
                string fileNameTest = Path.GetDirectoryName(exeLocation) + Path.DirectorySeparatorChar + fileName;
                fileName = fileNameTest + DumpExtension;
                int i = 0;
                while(File.Exists(fileName))
                {
                    fileName = string.Format("{0}_{1}{2}", fileNameTest, i.ToString("00"), DumpExtension);
                    i++;
                }
                using (TextWriter writer = new StreamWriter(fileName))
                {
                    foreach (string s in args)
                    {
                        writer.Write(s);
                        writer.Write(writer.NewLine);
                    }
                }
            }
        }
    }
}
